package com.tengju.user.application.archives.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

@Data
@ApiModel(value = "PageQueryDTO", description = "公共的分页参数对象")
public class PageQueryDTO implements Serializable {

    /** */
    private static final long serialVersionUID = 1L;
    
    @ApiModelProperty(value = "页大小，默认为10", required = true)
    @NotNull(message = "分页参数不能为空")
    @Min(value = 1)
    private Integer pageSize = 10;
    
    @ApiModelProperty(value = "页码，默认为1（第一页）", required = true)
    @NotNull(message = "页码不能为空")
    @Min(value = 1)
    private Integer pageIndex = 1;

    @JsonIgnore
    private Integer offset;

    public Integer getOffset() {
        return Math.max((pageIndex - 1) * pageSize,0);
    }
}
